package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysInform;
import com.zuthub.system.service.ISysInformService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 * 
 * @author zuthub
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/system/inform")
public class SysInformController extends BaseController
{
    @Autowired
    private ISysInformService sysInformService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:inform:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysInform sysInform)
    {
        startPage();
        List<SysInform> list = sysInformService.selectSysInformList(sysInform);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysInform sysInform)
    {
        startPage();
        List<SysInform> list = sysInformService.selectSysInformList(sysInform);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:inform:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysInform sysInform)
    {
        List<SysInform> list = sysInformService.selectSysInformList(sysInform);
        ExcelUtil<SysInform> util = new ExcelUtil<SysInform>(SysInform.class);
        return util.exportExcel(list, "inform");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:inform:query')")
    @GetMapping(value = "/{informId}")
    public AjaxResult getInfo(@PathVariable("informId") Long informId)
    {
        return AjaxResult.success(sysInformService.selectSysInformById(informId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:inform:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysInform sysInform)
    {
        return toAjax(sysInformService.insertSysInform(sysInform));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:inform:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysInform sysInform)
    {
        return toAjax(sysInformService.updateSysInform(sysInform));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:inform:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{informIds}")
    public AjaxResult remove(@PathVariable Long[] informIds)
    {
        return toAjax(sysInformService.deleteSysInformByIds(informIds));
    }
}
